Merged
Conversation
In prep for generating structs for variant types in the C backend, start collecting variant types in the record type collector. Record type collector renamed as type collector as it collects both records and variants now.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In prep for value types, this makes variant types unboxed.
For example,
[E1, E2, E3]generates this C struct:This struct is then used directly, instead of as a pointer.
The tag is the tag of the variant's wrapped value. E.g. if the variant value is
E1, the tag is the tag ofE1. IfE1is a sum type, then it's the tag ofthe constructor.
(Because each constructor (rather than type) has a unique constructor, we can
use the constructor's type as variant tags.)
This means that we always check the tag once when matching a variant value,
regardless of the values in the variant. (sums or products, boxed or unboxed)
Variants are still assigned heap object indices, but those indices are not used
in runtime. They're used in compile time to refer to variant types during
dependency analysis (and probably other places too).
Variant type refinements: we now annotate AST nodes with refined types of
variant binders. The generated code then unpacks the original value and packs
again as the value expected by the binder. Example:
Compiled to: (relevant parts)
This part of the generated code is not properly indented/formatted yet, example
above formatted manually with clang-format.
We should generate variant conversions outlined, in a separate function.
The "invalid variant conversion" is there to make debugging easier. That branch
won't be taken unless there's a bug in the compiler.
Fixes #279.